package com.drk.farmseason;

import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.input.touch.TouchEvent;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;
import org.anddev.andengine.util.Debug;

import android.widget.Toast;

public class customsprite extends AnimatedSprite {
private FarmSeasonActivity farmSeasonActivity;
	public customsprite(float locx, float locY,
			TiledTextureRegion pTiledTextureRegion) {
		super(locx, locY, pTiledTextureRegion);
		// TODO Auto-generated constructor stub
		
		
	}
	public customsprite(int locx, int locY, TiledTextureRegion pTiledTextureRegion,
			FarmSeasonActivity farmSeasonActivityy) {
		super(locx, locY, pTiledTextureRegion);
		this.farmSeasonActivity = farmSeasonActivityy;
		//mScene.registerTouchArea(this);
		//mScene.getLastChild().attachChild(this);
		// TODO Auto-generated constructor stub
	}

	@Override
    public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
		if(pSceneTouchEvent.isActionUp()){
			Debug.d("sprite touched index is =" + this.getCurrentTileIndex());
			if(this.getCurrentTileIndex() < 2) {
				this.setCurrentTileIndex(this.getCurrentTileIndex() + 1);
				return true;
			} else {
				final customsprite csss = this;
				farmSeasonActivity.runOnUpdateThread(new Runnable() {
					@Override
					public void run() {
						/* Now it is save to remove the entity! */
						farmSeasonActivity.getEngine().getScene().unregisterTouchArea(csss);
						farmSeasonActivity.getEngine().getScene().getLastChild().detachChild(csss);
					}
				});
			}

		}
		return true;
    }

}
